package java8Test.function.lambda.part2;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ThreadLocalLambdaTest {

    private static final ThreadLocal<DateFormat> threadLocal = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd"));

    public static void main(String[] args) {
        try {
            Date parse = threadLocal.get().parse("1970-01-01 00:00:01");
            System.out.println(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(() -> {
                Thread t = Thread.currentThread();
                System.out.println(t.getName());
                System.out.println(threadLocal.get());
            });
            thread.start();
        }
    }
}
